package com.ht.controller;

import cn.hutool.core.bean.BeanUtil;
import com.ht.data.Result;
import com.ht.domain.bo.TbDepartmentBO;
import com.ht.domain.bo.TbDoctorBO;
import com.ht.domain.vo.TbDoctorVO;
import com.ht.dto.TbDepartmentDTO;
import com.ht.dto.TbDiagnoseOrderDTO;
import com.ht.dto.TbDoctorDTO;
import com.ht.service.TbDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController  //等于@Restquest + @Controller
@RequestMapping("/sideEffect")
@Api("药物副作用门诊挂号管理系统")
@RefreshScope  //实时刷新
public class SideEffectController {

    @Autowired
    private TbDepartmentService tbDepartmentService;

    @Autowired
    private PublicOutpatientController publicOutpatientController;

    /**
     * 根据科室名称查询药剂科
     * @param departmentName 科室名称
     * @return
     */
    @PostMapping("/queryDepartmentBydepartmentName")
    @ApiOperation("根据科室名称查询药剂科")
    @ApiImplicitParam()
    public Result queryDepartmentBydepartmentName(@RequestParam String departmentName){
        List<TbDoctorBO> list = tbDepartmentService.queryDepartmentBydepartmentName(departmentName);
        List<TbDoctorVO> listt = new ArrayList<>();
        list.forEach(obj->{
            TbDoctorVO vo = new TbDoctorVO();
            BeanUtil.copyProperties(obj,vo);
            listt.add(vo);
        });
        return Result.OK().setData(listt);
    }



    @PostMapping("/queryDepartmentByPicturePrice")
    @ApiOperation("药剂师服务选择")
    @ApiImplicitParam()
    public Result queryDepartmentByPicturePrice(TbDoctorDTO dto){
        TbDiagnoseOrderDTO o = new TbDiagnoseOrderDTO();
        o.setOrderTypes(dto.getOrderTypes());//订单类型
        o.setOrderType(dto.getDepartmentName()); //挂号科室
        o.setDoctorNanme(dto.getDoctorName());//医生姓名
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String format = sdf.format(new Date());//挂号看病的时间
        o.setOpenStatus(dto.getPrivateStatus());//门诊方式
        o.setPrice(dto.getOutpatientFirstPrice().toString()); //费用
        o.setHeight(dto.getHeight());//患者身高
        o.setWeight(dto.getWeight());//患者体重
        o.setAllergyDetails(dto.getAllergyDetails());
        o.setDescribe(dto.getDescribe());//是否有过敏史
        o.setFormat(format);//患者病情描述
        publicOutpatientController.registeredSeven(o);
        return Result.OK();
    }




}
